package com.zhangxin.ch1;

import java.util.Scanner;

public class UnionSort {
    private static int N = 100010;

    private static int[] tmpArr = new int[N];

    public static void main(String[] args) {
        Scanner scanner = new Scanner(System.in);
        int n = scanner.nextInt();
        int[] arr = new int[n];
        for (int i = 0; i < n; i++) {
            arr[i] = scanner.nextInt();
        }

        unionSort(arr, 0, n - 1);

        for (int i = 0; i < n; i++) {
            System.out.print(arr[i] + " ");
        }
    }

    private static void unionSort(int[] arr, int left, int right) {
        if (left >= right) {
            return;
        }
        int mid = left + right >> 1;
        unionSort(arr, left, mid);
        unionSort(arr, mid + 1, right);

        int i = left;
        int j = mid + 1;
        int k = 0;
        while (i <= mid && j <= right) {
            if (arr[i] < arr[j]) {
                tmpArr[k++] = arr[i++];
            } else {
                tmpArr[k++] = arr[j++];
            }
        }
        while (i <= mid) {
            tmpArr[k++] = arr[i++];
        }
        while (j <= right) {
            tmpArr[k++] = arr[j++];
        }

        for (int start = left, index = 0; start <= right; start++, index++) {
            arr[start] = tmpArr[index];
        }
    }
}
